1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.Filter;
26 
27 private import gobject.ObjectG;
28 private import gobject.Signals;
29 private import gtk.c.functions;
30 public  import gtk.c.types;
31 private import std.algorithm;
32 
33 
34 /**
35  * A `GtkFilter` object describes the filtering to be performed by a
36  * [class@Gtk.FilterListModel].
37  * 
38  * The model will use the filter to determine if it should include items
39  * or not by calling [method@Gtk.Filter.match] for each item and only
40  * keeping the ones that the function returns %TRUE for.
41  * 
42  * Filters may change what items they match through their lifetime. In that
43  * case, they will emit the [signal@Gtk.Filter::changed] signal to notify
44  * that previous filter results are no longer valid and that items should
45  * be checked again via [method@Gtk.Filter.match].
46  * 
47  * GTK provides various pre-made filter implementations for common filtering
48  * operations. These filters often include properties that can be linked to
49  * various widgets to easily allow searches.
50  * 
51  * However, in particular for large lists or complex search methods, it is
52  * also possible to subclass `GtkFilter` and provide one's own filter.
53  */
54 public class Filter : ObjectG
55 {
56 	/** the main Gtk struct */
57 	protected GtkFilter* gtkFilter;
58 
59 	/** Get the main Gtk struct */
60 	public GtkFilter* getFilterStruct(bool transferOwnership = false)
61 	{
62 		if (transferOwnership)
63 			ownedRef = false;
64 		return gtkFilter;
65 	}
66 
67 	/** the main Gtk struct as a void* */
68 	protected override void* getStruct()
69 	{
70 		return cast(void*)gtkFilter;
71 	}
72 
73 	/**
74 	 * Sets our main struct and passes it to the parent class.
75 	 */
76 	public this (GtkFilter* gtkFilter, bool ownedRef = false)
77 	{
78 		this.gtkFilter = gtkFilter;
79 		super(cast(GObject*)gtkFilter, ownedRef);
80 	}
81 
82 
83 	/** */
84 	public static GType getType()
85 	{
86 		return gtk_filter_get_type();
87 	}
88 
89 	/**
90 	 * Notifies all users of the filter that it has changed.
91 	 *
92 	 * This emits the [signal@Gtk.Filter::changed] signal. Users
93 	 * of the filter should then check items again via
94 	 * [method@Gtk.Filter.match].
95 	 *
96 	 * Depending on the @change parameter, not all items need to
97 	 * be changed, but only some. Refer to the [enum@Gtk.FilterChange]
98 	 * documentation for details.
99 	 *
100 	 * This function is intended for implementors of `GtkFilter`
101 	 * subclasses and should not be called from other functions.
102 	 *
103 	 * Params:
104 	 *     change = How the filter changed
105 	 */
106 	public void changed(GtkFilterChange change)
107 	{
108 		gtk_filter_changed(gtkFilter, change);
109 	}
110 
111 	/**
112 	 * Gets the known strictness of @filters.
113 	 *
114 	 * If the strictness is not known, %GTK_FILTER_MATCH_SOME is returned.
115 	 *
116 	 * This value may change after emission of the [signal@Gtk.Filter::changed]
117 	 * signal.
118 	 *
119 	 * This function is meant purely for optimization purposes, filters can
120 	 * choose to omit implementing it, but `GtkFilterListModel` uses it.
121 	 *
122 	 * Returns: the strictness of @self
123 	 */
124 	public GtkFilterMatch getStrictness()
125 	{
126 		return gtk_filter_get_strictness(gtkFilter);
127 	}
128 
129 	/**
130 	 * Checks if the given @item is matched by the filter or not.
131 	 *
132 	 * Params:
133 	 *     item = The item to check
134 	 *
135 	 * Returns: %TRUE if the filter matches the item and a filter model should
136 	 *     keep it, %FALSE if not.
137 	 */
138 	public bool match(ObjectG item)
139 	{
140 		return gtk_filter_match(gtkFilter, (item is null) ? null : item.getObjectGStruct()) != 0;
141 	}
142 
143 	/**
144 	 * Emitted whenever the filter changed.
145 	 *
146 	 * Users of the filter should then check items again via
147 	 * [method@Gtk.Filter.match].
148 	 *
149 	 * `GtkFilterListModel` handles this signal automatically.
150 	 *
151 	 * Depending on the @change parameter, not all items need
152 	 * to be checked, but only some. Refer to the [enum@Gtk.FilterChange]
153 	 * documentation for details.
154 	 *
155 	 * Params:
156 	 *     change = how the filter changed
157 	 */
158 	gulong addOnChanged(void delegate(GtkFilterChange, Filter) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
159 	{
160 		return Signals.connect(this, "changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
161 	}
162 }